//
//  VKJiFenShopDHChildController.m
//  V-Learn
//
//  Created by liubo on 2019/1/9.
//  Copyright © 2019 yxk. All rights reserved.
//

#import "VKJiFenShopDHChildController.h"
#import "VKMeJiFenChildCell.h"

@interface VKJiFenShopDHChildController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) NSMutableArray *dataArray;
@property (nonatomic, strong) UITableView *tableView;

@end

@implementation VKJiFenShopDHChildController
- (instancetype)initWithID:(NSString *)uid
{
    self = [super init];
    if (self) {
        self.uid = uid;
    }
    return self;
}
-(NSMutableArray *)dataArray{
    if (_dataArray == nil) {
        _dataArray = [[NSMutableArray alloc]init];
    }
    return _dataArray;
}
-(UITableView *)tableView{
    if (_tableView == nil) {
        _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, [UIScreen cz_screenWidth], [UIScreen cz_screenHeight] - LBNAVBAR_HEIGHT) style:UITableViewStylePlain];
        _tableView.tableFooterView = [UIView new];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [self.view addSubview:_tableView];
        _tableView.backgroundColor = [UIColor cz_colorWithRed:244 green:244 blue:244];
    }
    return _tableView;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.edgesForExtendedLayout = @[];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [self tableView];
    [self setupData];
}

- (void)setupData{
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
    hud.labelText = @"正在加载...";
    [hud show:YES];
    NSMutableDictionary *pagramsD = @{@"token":[UserModel getUserModel].token,@"shipmentsStatus":self.uid}.mutableCopy;
    [WYHXNetWorkService netWorkSerViceRequestWithGetUrl:WKStudyMyQueryIntegralExchangeRecord withPostParams:pagramsD withBlock:^(NSDictionary *result, NSError *error) {
        hud.hidden = YES;
        if ([result[@"code"]integerValue] == 200) {
            
            self.dataArray = [VKMeJiFenChildModel mj_objectArrayWithKeyValuesArray:result[@"data"]];
//            [MBProgressHUD showSuccess:@"提交成功" toView:self.view];
        }else{
            [MBProgressHUD showSuccess:@"提交失败" toView:self.view];
        }
        [self.tableView reloadData];
    }];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 64;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.dataArray.count;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    VKMeJiFenChildCell *cell = [VKMeJiFenChildCell cellWithTableView:tableView];
//        cell.model = self.dataArray[indexPath.row];
    VKMeJiFenChildModel *moddel = self.dataArray[indexPath.row];
    cell.model =  moddel;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
